#define  _CRT_SECURE_NO_WARNINGS

#define  _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<vector>
#include<assert.h>
using namespace std;

namespace bit
{
	template<class T>
	class vector
	{
	public:
			typedef T* iterator;
			typedef const T* const_iterator;

			const_iterator begin() const
			{
				return _start;
			}

			const_iterator end() const
			{
				return _finish;
			}

			iterator begin()
			{
				return _start;
			}

			iterator end()
			{
				return _finish;
			}

			vector() = default;

			vector(const vector<T>& v)
			{
				//reserve();
				for (auto e : v)
				{
					push_back(e);
				}
			}


		~vector()
		{
			if (_start)
			{
				delete[] _start;
				_start = _finish = _end_of_storage = nullptr;
			}
		}

		T& operator[](size_t i)
		{
			assert(i < size());
			return _start[i];
		}

		size_t size() const
		{
			return _finish - _start;
		}

		size_t capacity() const
		{
			return _end_of_storage - _start;
		}

		void reserve(size_t n)
		{
			if (n > capacity())
			{
				size_t oldsize = size();
				T* tmp = new T[n];
				if (_start)
				{
					memcpy(tmp, _start, sizeof(T*) * size());
					delete[] _start;
				}
				_start = tmp;
				_finish = _start + oldsize;
				_end_of_storage = _start + n;
			}
		}

		void push_back(const T x)
		{
			//if (_finish == _end_of_storage)
			//{
			//	size_t newcapacity = capacity() == 0 ? 4 : capacity() * 2;
			//	reserve(newcapacity);
			//}
			//*_finish = x;
			//++_finish;

			insert(end(), x);
		}

		void pop_back()
		{
			assert(size() > 0);
			--_finish;
		}

		iterator insert(iterator pos, const T& x)
		{
			assert(pos >= _start);
			assert(pos <= _finish);
			if (_finish == _end_of_storage)
			{
				size_t len = pos - _start;
				size_t newcapacity = capacity() == 0 ? 4 : capacity() * 2;
				reserve(newcapacity);
				pos = _start + len;
			}
			iterator end = _finish - 1;
			while (end >= pos)
			{
				*(end + 1) = *end;
				--end;
			}
			*pos = x;
			_finish++;
			return pos;
		}

		iterator earse(iterator pos)
		{
			assert(pos >= _start);
			assert(pos < _finish);
			iterator it = pos + 1;
			while (it != _finish)
			{
				*(it - 1) = *it;
				it++;
			}
			--_finish;
			iterator pos;
		}

		//void find(const T& x)
		

	private:
		iterator _start = nullptr;
		iterator _finish = nullptr;
		iterator _end_of_storage = nullptr;
	};

	void test_vector1()
	{
		vector<int> v1;
		v1.push_back(1);
		v1.push_back(2);
		v1.push_back(3);
		v1.push_back(4);
		v1.push_back(5);
		v1.push_back(6);
		v1.earse(v1.begin());

		/*		for (size_t i = 0; i < v1.size(); i++)
				{
					cout << v1[i] << " ";
				}
				cout << endl*/;


				for (auto e : v1)
				{
					cout << e << " ";
				}
				cout << endl;
	}

	//vector<int>::iterator it1 = v1.begin();
	//while (it1!=v1.end())
}